<?php
if (!extension_loaded('xdebug')) {
    if (!defined('SXOMQOPOWWSCQOXDRNQMNEGAJULDYJVW') || SXOMQOPOWWSCQOXDRNQMNEGAJULDYJVW != 'DECKPHP') {
        exit('请勿删除DECK加密版权！By Moyu');
    }
    include '../meihe/common.php';
    include '../user/haohl.php';
    $dlfs = $_GET['dlfs'];
    if (!($dlfs == 'wx')) {
        if (!($dlfs == 'qq')) {
            if (!($dlfs == 'xb')) {
                exit('<script language=\'javascript\'>alert(\'登录方式不存在！\');window.location.href=\'./\';</script>');
            }
            if ($conf['xbfl_open'] != 0x1) {
                exit('<script language=\'javascript\'>alert(\'支付宝登录未开启！无法使用\');window.location.href=\'../\';</script>');
            }
            $Oauth_config['apiurl'] = $conf['xbfl_url'];
            $Oauth_config['appid'] = $conf['xbfl_id'];
            $Oauth_config['appkey'] = $conf['xbfl_key'];
            $Oauth_config['callback'] = $conf['fhh_url'] . '/quick.php?dlfs=xb';
            $type = 'alipay';
            if (!$_GET['code']) {
                $Oauth = new Oauth($Oauth_config);
                $arr = $Oauth->{'login'}($type);
                if (!(isset($arr['code']) && $arr['code'] == 0)) {
                    if (!isset($arr['code'])) {
                        exit('<script language=\'javascript\'>alert(\'获取登录地址失败！\');window.location.href=\'./\';</script>');
                    }
                    exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
                }
                exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
            }
            if ($_GET['state'] != $_SESSION['Oauth_state']) {
                exit('<script language=\'javascript\'>alert(\'登录失败: 状态不匹配。您可能是CSRF的受害者。\');window.location.href=\'../\';</script>');
            }
            $Oauth = new Oauth($Oauth_config);
            $arr = $Oauth->{'callback'}();
            if (!(isset($arr['code']) && $arr['code'] == 0)) {
                if (!isset($arr['code'])) {
                    exit('获取登录数据失败');
                }
                exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
            }
            $openid = $arr['social_uid'];
            $access_token = $arr['access_token'];
            $_SESSION['user'] = $arr;
            if ($islogin) {
                if (!($conf['access_token2'] == $access_token)) {
                    saveSetting('access_token2', $access_token);
                    saveSetting('xbmz', $_SESSION['user']['nickname']);
                    @header('Content-Type: text/html; charset=UTF-8');
                    exit('<script language=\'javascript\'>alert(\'恭喜您绑定或更换支付宝成功！\');window.location.href=\'./\';</script>');
                }
                @header('Content-Type: text/html; charset=UTF-8');
                exit('<script language=\'javascript\'>alert(\'该支付宝已绑定其他用户！\');history.go(-1);</script>');
            }
            if ($conf['access_token2']) {
                if (!($conf['access_token2'] == $access_token)) {
                    exit;
                }
                $user = $conf['admin_user'];
                $pass = $conf['admin_pwd'];
                $session = md5($user . $pass . $password_hash);
                $token = authcode("{$user}\t{$session}", 'ENCODE', SYS_KEY);
                $_SESSION['admin_token'] = $token;
                @header('Content-Type: text/html; charset=UTF-8');
                exit('<script language=\'javascript\'>alert(\'登录成功,欢迎回来!\');window.location.href=\'./\';</script>');
            }
            @header('Content-Type: text/html; charset=UTF-8');
            exit('<script language=\'javascript\'>alert(\'该支付宝未绑定用户！\');history.go(-1);</script>');
        }
        if ($conf['qqfl_open'] != 0x2 && $conf['qqfl_open'] != 0x1) {
            exit('<script language=\'javascript\'>alert(\'QQ登录未开启！无法使用\');window.location.href=\'../\';</script>');
        } else {
        }
        if (!($conf['qqfl_open'] == 0x1)) {
            if ($conf['qqfl_open'] == 0x2) {
                $Oauth_config['apiurl'] = $conf['qqfl_url'];
                $Oauth_config['appid'] = $conf['qqfl_id'];
                $Oauth_config['appkey'] = $conf['qqfl_key'];
                $Oauth_config['callback'] = $conf['fhh_url'] . '/quick.php?dlfs=qq';
                $type = 'qq';
                if (!$_GET['code']) {
                    $Oauth = new Oauth($Oauth_config);
                    $arr = $Oauth->{'login'}($type);
                    if (!(isset($arr['code']) && $arr['code'] == 0)) {
                        if (!isset($arr['code'])) {
                            exit('<script language=\'javascript\'>alert(\'获取登录地址失败！\');window.location.href=\'./\';</script>');
                        }
                        exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
                    }
                    exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
                }
                if ($_GET['state'] != $_SESSION['Oauth_state']) {
                    exit('<script language=\'javascript\'>alert(\'登录失败: 状态不匹配。您可能是CSRF的受害者。\');window.location.href=\'../\';</script>');
                } else {
                }
            } else {
                $Oauth_config['appid'] = $conf['qqfl_id'];
                $Oauth_config['appkey'] = $conf['qqfl_key'];
                $Oauth_config['callback'] = $conf['fhh_url'] . '/quick.php?dlfs=qq';
                $type = 'qq';
                if (!$_GET['code']) {
                    $Oauth = new Oauth($Oauth_config);
                    $arr = $Oauth->{'login'}($type);
                    if (!(isset($arr['code']) && $arr['code'] == 0)) {
                        if (!isset($arr['code'])) {
                            exit('<script language=\'javascript\'>alert(\'获取登录地址失败！\');window.location.href=\'./\';</script>');
                        }
                        exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
                    }
                    exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
                }
                if ($_GET['state'] != $_SESSION['Oauth_state']) {
                    exit('<script language=\'javascript\'>alert(\'登录失败: 状态不匹配。您可能是CSRF的受害者。\');window.location.href=\'../\';</script>');
                } else {
                }
            }
        } else {
            $Oauth_config['apiurl'] = 'http://hl.haohaofh.com/';
            $Oauth_config['appid'] = $conf['qqfl_id'];
            $Oauth_config['appkey'] = $conf['qqfl_key'];
            $Oauth_config['callback'] = $conf['fhh_url'] . '/quick.php?dlfs=qq';
            $type = 'qq';
            if (!$_GET['code']) {
                $Oauth = new Oauth($Oauth_config);
                $arr = $Oauth->{'login'}($type);
                if (!(isset($arr['code']) && $arr['code'] == 0)) {
                    if (!isset($arr['code'])) {
                        exit('<script language=\'javascript\'>alert(\'获取登录地址失败！\');window.location.href=\'./\';</script>');
                    }
                    exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
                }
                exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
            }
            if ($_GET['state'] != $_SESSION['Oauth_state']) {
                exit('<script language=\'javascript\'>alert(\'登录失败: 状态不匹配。您可能是CSRF的受害者。\');window.location.href=\'../\';</script>');
            } else {
            }
        }
        $Oauth = new Oauth($Oauth_config);
        $arr = $Oauth->{'callback'}();
        if (!(isset($arr['code']) && $arr['code'] == 0)) {
            if (!isset($arr['code'])) {
                exit('获取登录数据失败');
            }
            exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
        }
        $openid = $arr['social_uid'];
        $access_token = $arr['access_token'];
        $_SESSION['user'] = $arr;
        if ($islogin) {
            if (!($conf['access_tokenn'] == $access_token)) {
                saveSetting('access_tokenn', $access_token);
                saveSetting('qqmz', $_SESSION['user']['nickname']);
                @header('Content-Type: text/html; charset=UTF-8');
                exit('<script language=\'javascript\'>alert(\'恭喜您绑定或更换QQ成功！\');window.location.href=\'./\';</script>');
            }
            @header('Content-Type: text/html; charset=UTF-8');
            exit('<script language=\'javascript\'>alert(\'该QQ已绑定其他用户！\');history.go(-1);</script>');
        }
        if ($conf['access_tokenn']) {
            if (!($conf['access_tokenn'] == $access_token)) {
                exit;
            }
            $user = $conf['admin_user'];
            $pass = $conf['admin_pwd'];
            $session = md5($user . $pass . $password_hash);
            $token = authcode("{$user}\t{$session}", 'ENCODE', SYS_KEY);
            $_SESSION['admin_token'] = $token;
            @header('Content-Type: text/html; charset=UTF-8');
            exit('<script language=\'javascript\'>alert(\'登录成功,欢迎回来!\');window.location.href=\'./\';</script>');
        }
        @header('Content-Type: text/html; charset=UTF-8');
        exit('<script language=\'javascript\'>alert(\'该QQ未绑定用户！\');history.go(-1);</script>');
    }
    if ($conf['wxfl_open'] != 0x1) {
        exit('<script language=\'javascript\'>alert(\'微信登录未开启！无法使用\');window.location.href=\'../\';</script>');
    }
    $Oauth_config['apiurl'] = $conf['wxfl_url'];
    $Oauth_config['appid'] = $conf['wxfl_id'];
    $Oauth_config['appkey'] = $conf['wxfl_key'];
    $Oauth_config['callback'] = $conf['fhh_url'] . '/quick.php?dlfs=wx';
    $type = 'wx';
    if (!$_GET['code']) {
        $Oauth = new Oauth($Oauth_config);
        $arr = $Oauth->{'login'}($type);
        if (!(isset($arr['code']) && $arr['code'] == 0)) {
            if (!isset($arr['code'])) {
                exit('<script language=\'javascript\'>alert(\'获取登录地址失败！\');window.location.href=\'./\';</script>');
            }
            exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
        }
        exit("<script language='javascript'>window.location.href='{$arr['url']}';</script>");
    }
    if ($_GET['state'] != $_SESSION['Oauth_state']) {
        exit('<script language=\'javascript\'>alert(\'登录失败: 状态不匹配。您可能是CSRF的受害者。\');window.location.href=\'./\';</script>');
    }
    $Oauth = new Oauth($Oauth_config);
    $arr = $Oauth->{'callback'}();
    if (!(isset($arr['code']) && $arr['code'] == 0)) {
        if (!isset($arr['code'])) {
            exit('获取登录数据失败');
        }
        exit("<script language='javascript'>alert('登录接口返回: {$arr['msg']}');window.location.href='./';</script>");
    }
    $openid = $arr['social_uid'];
    $access_token = $arr['access_token'];
    $_SESSION['user'] = $arr;
    if ($islogin) {
        if (!($conf['access_token'] == $openid)) {
            saveSetting('access_token', $openid);
            saveSetting('wxmz', $_SESSION['user']['nickname']);
            @header('Content-Type: text/html; charset=UTF-8');
            exit('<script language=\'javascript\'>alert(\'恭喜您绑定或更换微信成功！\');window.location.href=\'./\';</script>');
        }
        @header('Content-Type: text/html; charset=UTF-8');
        exit('<script language=\'javascript\'>alert(\'该微信已绑定其他用户！\');history.go(-1);</script>');
    }
    if ($conf['access_token']) {
        if ($conf['access_token'] == $openid) {
            $user = $conf['admin_user'];
            $pass = $conf['admin_pwd'];
            $session = md5($user . $pass . $password_hash);
            $token = authcode("{$user}\t{$session}", 'ENCODE', SYS_KEY);
            $_SESSION['admin_token'] = $token;
            @header('Content-Type: text/html; charset=UTF-8');
            exit('<script language=\'javascript\'>alert(\'登录成功,欢迎回来!\');window.location.href=\'./\';</script>');
        }
        exit;
    }
    @header('Content-Type: text/html; charset=UTF-8');
    exit('<script language=\'javascript\'>alert(\'该微信未绑定用户！\');history.go(-1);</script>');
}
exit('请先卸载xDebug拓展');
